    // 学生详情模态框相关变量
    const studentModal = document.getElementById('studentModal');
    const closeModalBtn = document.getElementById('closeStudentModal');
    const modalContent = document.getElementById('studentModalContent');
    const studentTableBody = document.getElementById('studentTableBody');
    const searchForm = document.getElementById('studentSearchForm');

    // 打开学生详情模态框
    function openStudentModal(studentId) {
    fetch(`/teacher/student/detail/${studentId}`, {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'X-CSRFToken': '{{ csrf_token() }}' // 保留 CSRF 保护（如有需要）
        }
    })
    .then(response => {
        if (!response.ok) {
            throw new Error('请求失败');
        }
        return response.json();
    })
    .then(responseData => {
        // 关键修正：从 responseData.data 中获取 student_data
        const student = responseData.data; // 后端返回的 data 字段包含 student_data 对象

        // 填充模态框内容（直接使用 student 中的字段）
        document.getElementById('detailStudentNo').textContent = student.student_no || '未记录';
        document.getElementById('detailStudentName').textContent = student.username || '未记录';
        document.getElementById('detailStudentGender').textContent = student.gender || '未指定';
        document.getElementById('detailStudentAge').textContent = student.age || '未记录';
        document.getElementById('detailStudentClass').textContent = student.class_name || '未分配班级';
        document.getElementById('detailStudentMajor').textContent = student.major || '未指定';
        document.getElementById('detailStudentPhone').textContent = student.telephone || '未提供';
        document.getElementById('detailStudentAddress').textContent = student.address || '未提供';

        // 显示模态框
        studentModal.classList.remove('opacity-0', 'pointer-events-none');
        studentModal.classList.add('opacity-100', 'pointer-events-auto');
        modalContent.classList.remove('scale-95');
        modalContent.classList.add('scale-100');
    })
    .catch(error => {
        console.error('获取学生详情失败:', error);
        alert('获取学生信息失败，请检查网络或重试');
    });
}

    // 关闭学生详情模态框
    function closeStudentModal() {
        studentModal.classList.add('opacity-0', 'pointer-events-none');
        studentModal.classList.remove('opacity-100', 'pointer-events-auto');
        modalContent.classList.remove('scale-100');
        modalContent.classList.add('scale-95');
    }

    // 模态框关闭事件监听
    closeModalBtn.addEventListener('click', closeStudentModal);
    studentModal.addEventListener('click', (e) => {
        if (e.target === studentModal) {
            closeStudentModal();
        }
    });

    // 学生详情查看按钮点击事件
    studentTableBody.addEventListener('click', (e) => {
        if (e.target.classList.contains('view-student-btn')) {
            const studentId = e.target.dataset.studentId;
            openStudentModal(studentId);
        }
    });

